extends AnimatedSprite

onready var sprite = $Sprite
onready var heartLable = $HeartLable
var steps = 5
var mapSpend = {}
var canWalk:HashMap
var curPoint:Point = Point.new()
var walkType = 0
var mapTexture

func initEnemy(config:Dictionary, mapType):
	var configPosition:Vector2 = config.get("position")
	position = configPosition*32
	curPoint = Point.new()
	curPoint.init(configPosition.x, configPosition.y)
	walkType = config.get("walkType")
	mapTexture = get_parent().get_node("MapTexture")
	mapSpend = MapFunction.initMapSpend(walkType, mapType)

func go():
	var kuang = mapTexture.get_node("Kuang")
	kuang.position = curPoint.toVector() *32
	var reachPoints = ArrayList.new()
	reachPoints.add(curPoint)
	canWalk = CanWalk.getRoutPlan(mapSpend, ArraySet.new(), reachPoints, curPoint, steps, null, 30, 30)
	mapTexture.canWalkChange(canWalk.keys().arr)
	pass

func hurt():
	var truePosition = position
	heartLable.visible = true
#	yield(get_tree().create_timer(2),"timeout")
	
	var tween = Tween.new()
	add_child(tween)
	for i in range(5):
		var temp = Vector2(randi()%10, randi()%10)
		tween.interpolate_property(self, "position",
		truePosition, truePosition+temp, 0.1,
		Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
		tween.start()
		yield(tween,"tween_all_completed")
	heartLable.visible = false
	tween.queue_free()
	position = truePosition
